package com.itheima.sh.service.impl;

import com.itheima.sh.exception.ExceptionCast;
import com.itheima.sh.mapper.UserMapper;
import com.itheima.sh.pojo.User;
import com.itheima.sh.response.ResponseResult;
import com.itheima.sh.response.StatusCode;
import com.itheima.sh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @Description:
 * @Version: V1.0
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

    /**
     * 添加用户
     *
     * @param user
     * @return
     */
    @Override
    public User add(User user) {

        if (user.getUserName() == null) {
            ExceptionCast.cast( ResponseResult.errorResult( StatusCode.APUSER_USERNAMEISNULL_ERROR ) );
        }

        userMapper.add(user);
        return user;
    }

}
